#include ".\spritetext.h"

CBaseSpriteText::CBaseSpriteText(void)
{
	m_picText = NULL;
	m_hFont = NULL;
	m_hFont = myhoho_CreateFont(14);
}

CBaseSpriteText::~CBaseSpriteText(void)
{
	if (m_picText)
		GetGraphics()->RemoveBitmap(m_picText);
}

bool CBaseSpriteText::SetText(char* str)
{
	if (m_picText)
		GetGraphics()->RemoveBitmap(m_picText);
	m_picText = GetGraphics()->CreateBitmapFromTEXT(m_hFont, str, 0, P2D_COLOR_RED + 100);
	if (m_picText == NULL)
		return false;
	return true;
}

/*
void CBaseSpriteText::Draw(int x, int y)
{
	if (m_picText == NULL)
		return;
	int cx = x - m_picText->GetWidth();
	int cy = y - m_picText->GetHeight();
	GetGraphics()->DrawBitmap(CBaseSprite::m_x - cx , CBaseSprite::m_y - cy ,m_picText, SCREENBUFFER, true);
}
*/
bool CSpriteText::open(char * pFileName, char *name)
{
	if (CSprite::open(pFileName))
		return SetText(name);
	else
		return false;
}

void CSpriteText::Draw(int x, int y)
{
	CSprite::Draw(x, y);
	if (m_picText == NULL)
		return;
	int cx = x + (m_picText->GetWidth() - m_width) / 2;
	int cy = y + m_picText->GetHeight();
	GetGraphics()->DrawBitmap(m_x - cx , m_y - cy ,m_picText, SCREENBUFFER, true);
}

//---------------------------------------------------------------------------
bool C4SpriteText::open(char * pFileName, char *name)
{
	if (CSprite::open(pFileName))
		return SetText(name);
	else
		return false;
}

void C4SpriteText::Draw(int x, int y)
{
	C4Sprite::Draw(x, y);
	if (m_picText == NULL)
		return;
	int cx = x + (m_picText->GetWidth() - m_width) / 2;
	int cy = y + m_picText->GetHeight();
	GetGraphics()->DrawBitmap(m_x - cx , m_y - cy ,m_picText, SCREENBUFFER, true);
}

//---------------------------------------------------------------------------
bool CActionSpriteText::open(char * pFileName, char *name)
{
	if (CSprite::open(pFileName))
		return SetText(name);
	else
		return false;
}

void CActionSpriteText::Draw(int x, int y)
{
	CActionSprite::Draw(x, y);
	if (m_picText == NULL)
		return;
	int cx = x + (m_picText->GetWidth() - m_width) / 2;
	int cy = y + m_picText->GetHeight();
	GetGraphics()->DrawBitmap(m_x - cx , m_y - cy ,m_picText, SCREENBUFFER, true);
}

//---------------------------------------------------------------------------
bool C4aSpriteText::open(char * pFileName, char *name)
{
	if (CSprite::open(pFileName))
		return SetText(name);
	else
		return false;
}

void C4aSpriteText::Draw(int x, int y)
{
	C4aSprite::Draw(x, y);
	if (m_picText == NULL)
		return;
	int cx = x + (m_picText->GetWidth() - m_width) / 2;
	int cy = y + m_picText->GetHeight();
	GetGraphics()->DrawBitmap(m_x - cx , m_y - cy ,m_picText, SCREENBUFFER, true);
}